import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

public class updetaler implements LoginHandler {
    @Override
    public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String student_id = request.getParameter("student_id");
        String student_name = new String(request.getParameter("student_name").getBytes("ISO-8859-1"), "UTF-8");
        String student_age = request.getParameter("student_age");

        // 获取学生信息列表
        HttpSession session = request.getSession();
        ArrayList<String> studentInfo = (ArrayList<String>) session.getAttribute("studentInfo");

        // 遍历学生信息列表，查找与学生ID匹配的学生信息
        for (int i = 0; i < studentInfo.size(); i += 3) {
            if (studentInfo.get(i).equals(student_id)) {
                // 找到与学生ID匹配的学生信息
                studentInfo.set(i + 1, student_name);
                studentInfo.set(i + 2, student_age);
                break;
            }
        }
        response.sendRedirect("welcome.jsp");
    }
}
